﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BitPortal.Modules
{
    public partial class RichEditor : System.Web.UI.UserControl
    {
        protected string _DataType;
        private string _value;

        public string Value
        {
            set
            {
                _value = value;

                switch (DataType)
                {
                    case "Boolean":
                        Checkbox1.Checked = Convert.ToBoolean(value);
                        break;
                    case "String":
                        TextField1.Text = value;
                        break;
                    case "Text":
                        HtmlEditor1.Text = value;
                        break;
                    case "Interger":
                        NumberField1.Text = value;
                        break;
                    case "Double":
                        NumberField1.Text = value;
                        break;
                    case "Datetime":
                        DateField1.Text = value;
                        DateField1.SelectedDate = Convert.ToDateTime(value);
                        break;
                }
            }
            get
            {
                switch (DataType)
                {
                    case "Boolean":
                        return Checkbox1.Checked.ToString();
                    case "String":
                        return TextField1.Text;
                    case "Text":
                        return HtmlEditor1.Text;
                    case "Interger":
                        return NumberField1.Text;
                    case "Double":
                        return NumberField1.Text;
                    case "Datetime":
                        return DateField1.Text;
                }
                return "";
            }
        }

        public string DataType
        {
            set
            {
                this._DataType = value;
                Checkbox1.Hidden = TextField1.Hidden = NumberField1.Hidden = HtmlEditor1.Hidden = DateField1.Hidden = true;
                switch (value)
                {
                    case "Boolean":
                        Checkbox1.Hidden = false;
                        break;
                    case "String":
                        TextField1.Hidden = false;
                        break;
                    case "Text":
                        HtmlEditor1.Hidden = false;
                        break;
                    case "Interger":
                        NumberField1.Hidden = false;
                        NumberField1.AllowDecimals = false;
                        break;
                    case "Double":
                        NumberField1.Hidden = false;
                        NumberField1.AllowDecimals = true;
                        break;
                    case "Datetime":
                        DateField1.Hidden = false;
                        break;
                }
            }
            get
            {
                return this._DataType;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}